import React, { useState } from "react";

import reactLogo from "@/assets/react.svg";
import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom";
import "./Home.module.less";
import viteLogo from "/vite.svg";

const Home: React.FC = () => {
  const [count, setCount] = useState(0);
  const { i18n, t } = useTranslation();
  const navigate = useNavigate();

  return (
    <div>
      <div>
        <a href='https://vitejs.dev' target='_blank'>
          <img src={viteLogo} className='logo' alt='Vite logo' />
        </a>
        <a href='https://react.dev' target='_blank'>
          <img src={reactLogo} className='logo react' alt='React logo' />
        </a>
      </div>
      <h1>Vite + React</h1>
      <div className='card'>
        <button onClick={() => setCount((count) => count + 1)}>count is {count}</button>

        <p>
          Edit <code>src/App.jsx</code> and save to HMR
        </p>
      </div>
      <div className='card'>
        <button
          onClick={() => {
            window.deferredPromptClick();
          }}
        >
          Install App
        </button>
      </div>
      <p className='read-the-docs'>{t("common1")}</p>
      <p className='read-the-docs'>{t("common2")}</p>
      <div>
        <button
          onClick={() => {
            i18n.changeLanguage(i18n.language === "zh-CN" ? "en-US" : "zh-CN");
          }}
        >
          {t("common3")}
        </button>
      </div>
      <div>
        <button
          onClick={() => {
            navigate("/componentsPage");
          }}
        >
          {t("common4")}
        </button>
      </div>
    </div>
  );
};

export default Home;
